package com.wiz.web.controllor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wiz.common.ResponseCode;
import com.wiz.web.service.PayService;
import com.wiz.web.service.XlService;

@Controller
@RequestMapping("/p")
public class PayControllor implements ResponseCode{
	private transient final Logger log = LoggerFactory.getLogger(getClass());

	@Resource
	private PayService payService;
	@Resource
	private XlService xlService;

	@RequestMapping(value = "/bar", method = RequestMethod.POST)
	@ResponseBody
	public String barPay(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "order") String msg,
			@RequestParam(value = "hqId") String hqId,
			@RequestParam(value = "stationId") String stationId,
			@RequestParam(value = "payChannel") int payChannel,
			HttpSession session, Model model){
		try {
			request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
			String s = payService.barPay(msg, hqId, stationId, payChannel);
			return s;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("barpay fail! order= "+msg+" stationId="+stationId+"  payChannel="+payChannel,e);
			return RESPONSE_CODE_SERVER_ERROR;
		}
	}
	
	@RequestMapping(value = "/web", method = RequestMethod.POST)
	@ResponseBody
	public String webPay(HttpServletRequest request,HttpServletResponse response,
			@RequestParam(value = "order") String order,
			@RequestParam(value = "hqId") String hqId,
			@RequestParam(value = "stationId") String stationId,
			@RequestParam(value = "payChannel") int payChannel,
			HttpSession session, Model model){
		try {
			request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
			return payService.webPay(order, hqId, stationId, payChannel);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("webpay fail! order= "+order+" stationId="+stationId+"  payChannel="+payChannel,e);
			return RESPONSE_CODE_SERVER_ERROR;
		}
	}
}
